package com.atguigu.tingshu.user.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class weChatConfig {
    @Autowired
    private WechatAccountConfig wechatAccountConfig;

    @Bean
    public WxMaService wxMaService() {
        //创建对象
        WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();

        wxMaConfig.setAppid(wechatAccountConfig.getAppid());

        wxMaConfig.setSecret(wechatAccountConfig.getAppSecret());

        wxMaConfig.setMsgDataFormat("JSON");
        //创建WxMaService对象
        WxMaService wxMaService = new WxMaServiceImpl();
        //给WxMaService 设置配置选项
        wxMaService.setWxMaConfig(wxMaConfig);
        return wxMaService;
    }
}
